from vec3 import Vec3
from pointMass import PointMass
from spring import Spring
from solidMass import SolidMass

class Sheet(SolidMass):
    def __init__(self, mass = 1, stiffness = 1, rows = 3, cols = 3, pos = Vec3(), width = 10, height = 10):
        SolidMass.__init__(self)
        
        points = []
        dx = width / float(rows)
        dz = height / float(cols)
        for i in range(rows):
            points.append([])
            for j in range(cols):
                points[-1].append(PointMass(Vec3(pos.x + dx * i - width/2,
                                            pos.y,
                                            pos.z + dz * j - height/2)))
            self.pointMasses.extend(points[-1])

        for i in range(rows):
            for j in range(cols):
                if j < cols-1:
                    self.springs.append(Spring(points[i][j],points[i][j+1]))
                if i < rows - 1:
                    self.springs.append(Spring(points[i][j],points[i+1][j]))
                    if j < cols-1:
                        self.springs.append(Spring(points[i][j],points[i+1][j+1]))
                        self.springs.append(Spring(points[i+1][j],points[i][j+1]))

        for spring in self.springs:
            spring.stiffness = stiffness

        for pm in self.pointMasses:
            pm.mass = mass / float(len(self.pointMasses))
